<#include "macrosDisplay.ftl">
<#include "macroUtils.ftl">
<#include "macrosLoops.ftl">
package com.tps.gen.ui;

import java.util.List;

import javax.faces.model.DataModel;
import javax.faces.model.SelectItem;

import com.tps.framework.core.Entity;
import com.tps.framework.jsf.EntityHandler;
import com.tps.framework.jsf.RequiresParent;
import com.tps.gen.bo.*;

/**
 * <p>
 * A handler class for dealing with <@boLow/> objects.
 * </p>
 * 
 * <p>Created ${util.getDateString()}</p>
 * 
 * @author Archimedes
 * @version $Id$
 */
<@hasParents>public class <@boCap/>Handler extends EntityHandler implements RequiresParent {</@hasParents>
<@isRoot>public class <@boCap/>Handler extends EntityHandler {</@isRoot>
 
    <@isNotAbstract bo>
    /** 
     * @see com.tps.framework.jsf.EntityHandler#getConcreteClass()
     */
    @Override
    public Class<? extends Entity> getConcreteClass() {
        return <@boCap/>.class;
    }
    </@isNotAbstract>
 
    /**
     * @see com.tps.framework.jsf.EntityHandler#getHandlerUrl()
     */
    public String getHandlerUrl() {
        return "<@boLow/>.jsf";
    }

    /**
     * @see com.tps.framework.jsf.EntityHandler#getHandlerDisplayName()
     */
    public String getHandlerDisplayName() {
        return "<@boDisplay/>";
    }

    /** 
     * @see com.tps.framework.jsf.EntityHandler#getHandledClass()
     */
    protected Class<? extends Entity> getHandledClass() {
        return <@boCap/>.class;
    }
    
 //----------------------------------------------------------------------------
 	/** 
 	 * Sorters
 	 **/
 	<@meLoop>
	<#if !util.isBeanPathMember(member)>
 	public String setSortBy<@meCap/>() {
        this.setSortColumn("<@meLow/>");        
        return "success";
    }
    </#if>    
	</@meLoop>
	
 //----------------------------------------------------------------------------
 	/* 
 	 * Methods for M:M Internalized values
 	 */
 	 
 	<@MTMRelationshipsLoop>
 	<@isSource bo,relation>
    /**
     * Return a selectable list of <@cap relation.aliasTarget/> classes
     * @return
     */
    public List<SelectItem> getSelectable<@cap relation.aliasTarget/>s() {
    	<#if util.hasRestrictBeanPath(relation) >
	        return getSelectListValues(getCurrent(), "${relation.restrictBeanPath}");        
        <#else>
	        return getSelectListValues(<@childCap/>.class);			
        </#if>
    }

    /**
     * Return the selected <@cap relation.aliasTarget/> classes
     * @return
     */
    public List<String> getSelected<@cap relation.aliasTarget/>s() {
        return getSelectedChildren("${relation.display}", <@childCap/>.class);
    }

    /**
     * Set the selected <@cap relation.aliasTarget/> items
     * @param items
     */
    public void setSelected<@cap relation.aliasTarget/>s(List<Object> items) {
        setSelectedChildren("${relation.display}", items, <@childCap/>.class);
    }

    /**
     * Returns the selected children list as a data model for use in display.
     * 
     * @return
     */
    public DataModel get<@cap relation.aliasTarget/>s() {
        return getChildDataModel("${relation.display}", <@childCap/>.class);
    }
 	</@isSource>
 	
 	</@MTMRelationshipsLoop>
 	
 //----------------------------------------------------------------------------
 	/* 
 	 * Methods for M:1 Internalized values
 	 */
 	 
 	<@MTORelationshipsLoop>
    /**
     * Return a selectable list of <@cap relation.aliasTarget/> classes
     * @return
     */
    public List<SelectItem> getSelectable<@cap relation.aliasTarget/>s() {
    	<#if util.hasRestrictBeanPath(relation) >
			return getSelectListValues(getCurrent(), "${relation.restrictBeanPath}");        
        <#else>
	        return getSelectListValues(<@childCap/>.class);
        </#if>   
    }

    /**
     * Return the selected <@cap relation.aliasTarget/> classes
     * @return
     */
    public String getSelected<@cap relation.aliasTarget/>() {
        return getSelectedChild("${relation.display}", <@childCap/>.class);
    }

    /**
     * Set the selected <@cap relation.aliasTarget/> items
     * @param items
     */
    public void setSelected<@cap relation.aliasTarget/>(String item) {
        setSelectedChild("${relation.display}", item, <@childCap/>.class);
    }

    /**
     * Returns the selected children list as a data model for use in display.
     * 
     * @return
     */
    public DataModel get<@cap relation.aliasTarget/>s() {
        return getChildDataModel("${relation.display}", <@childCap/>.class);
    }
 	
 	</@MTORelationshipsLoop>
 	
 	// @SNIPPET@
}
